Overview
This document describes the mechanism of functional buttons support for the Opera TV Store.
Functional buttons allow content developers to use hardware buttons in their applications, despite the different characteristics of various hardware their application is used by. This is achieved by mapping hardware-specific key codes like “37” to more generic key codes (functional codes) like VK_LEFT.
Functional buttons provide support for such basic keys as left, right, up, down or select. They can also be used as shortcuts to commonly used functions, such as “options” or “red key”.
Functional buttons list and JS APIs
This API can easily be added to an application with the inclusion of the following script element:
Full API as specified in this document is available after such inclusion. Without the inclusion Javascript key codes such as VK_RED will be available but helper functions defined in the opera.tv object will not.
List of available functional buttons
Example hardware key |
JavaScript key code |
Comment |
| ← |
VK_LEFT |
Always available* |
| → |
VK_RIGHT |
Always available* |
| ↑ |
VK_UP |
Always available* |
| ↓ |
VK_DOWN |
Always available* |
| Confirm/Select/OK |
VK_ENTER |
Always available* |
| Exit |
N/A |
Always available
(handled by native firmware) |
| Back/Return |
VK_BACK_SPACE |
Optional
but recommended |
| BLUE |
VK_BLUE |
Optional
but recommended |
| RED |
VK_RED |
Optional
but recommended |
| GREEN |
VK_GREEN |
Optional
but recommended |
| YELLOW |
VK_YELLOW |
Optional
but recommended |
| Menu |
VK_MENU |
Optional |
| 0 |
VK_0 |
Optional |
| 1 |
VK_1 |
Optional |
| 2 |
VK_2 |
Optional |
| 3 |
VK_3 | Optional |
| 4 |
VK_4 | Optional |
| 5 |
VK_5 | Optional |
| 6 |
VK_6 | Optional |
| 7 |
VK_7 | Optional |
| 8 |
VK_8 | Optional |
| 9 |
VK_9 | Optional |
| PLAY |
VK_PLAY | Optional |
| PAUSE |
VK_PAUSE | Optional |
| STOP |
VK_STOP | Optional |
| NEXT |
VK_TRACK_NEXT | Optional |
| PREV |
VK_TRACK_PREV | Optional |
| FF
(Fast-Forward) |
VK_FAST_FWD | Optional |
| REWIND |
VK_REWIND | Optional |
| SUBTITLE |
VK_SUBTITLE | Optional |
| INFORMATION |
VK_INFO | Optional |
*Confirm, exit and directional buttons are mandatory, so they are always available for the end user via the remote control of any device that the Opera TV Store is integrated with. The exit key is handled by the native application to ensure that each application can be closed, therefore VK_EXIT will not be sent to the application.
Not supported buttons should return null value.
Buttons event API
Key events should be reached via standard JavaScript function or in HTML:
In HTML for a particular element:
<ELEMENT onkeypress="handler">
In JavaScript use one of the following:
object.onkeypress = handler;
object.addEventListener ("keypress", handler, useCapture);
object.attachEvent ("onkeypress", handler);
To get the pressed key, use: event.keyCode in the
handler function:
function handler(event){
if (VK_RED == event.keyCode){
ShowRedMenu();
}
}
List of available buttons API
The buttons list is reachable via the functional button object and contains the buttons list supported by the device with paths to the button’s graphic representation:
opera.tv.getButtonsList();
Key for returned list is button code and value of that key is button name. Example implementation of the getButtonsList function:
Return
{
[val(VK_LEFT)]: ‘VK_LEFT’,
[val(VK_BACK)]: ‘VK_BACK’,
[val(VK_MENU)]: ‘VK_MENU’
}
Example usage:
var list = opera.tv.getButtonsList();
Specific button check API
Availability of specific button can be checked as well as follows:
opera.tv.isButtonSupported(buttonID);
Returns true if a button with buttonID
exists and is supported by the device, or false if
it is not supported.
Example usage:
if(opera.tv.isButtonSupported(VK_RED))
ShowRedButton();
The same can be achieved with:
if(VK_RED)
ShowRedButton();